package com.lanlian.cayman.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanlian.cayman.R;
import com.lanlian.cayman.activity.KLineActivity;
import com.lanlian.cayman.bean.MinXiBean;
import com.lanlian.cayman.utils.MResUtil;
import com.lanlian.cayman.utils.NumberManager;
import com.lanlian.commonlib.bean.db.DBMarketS;
import com.lanlian.commonlib.dao.DBManager;
import com.lanlian.commonlib.data.ContractBean;


import java.util.List;

/**
 * <pre>

 * </pre>
 */
public class MinXiAdapter extends RecyclerView.Adapter<MinXiAdapter.MyViewHolder> {
    public int select=0;
    private Activity ka;
    String last_price="1";
    //② 创建ViewHolder
    public static class MyViewHolder extends RecyclerView.ViewHolder{
        public final TextView time;
        public final TextView price;
        public final TextView num;
        public MyViewHolder(View v) {
            super(v);
            time = (TextView) v.findViewById(R.id.time);
            price = (TextView) v.findViewById(R.id.price);
            num = (TextView) v.findViewById(R.id.num);

        }
    }
    private List<MinXiBean> mList;
    public MinXiAdapter(List<MinXiBean> mList) {
        this.mList=mList;
    }
    public void setData(List<MinXiBean> mList)
    {
        this.mList=mList;
    }

    //③ 在Adapter中实现3个方法
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {




        holder.time.setText(mList.get(position).time);
        holder.price.setText(mList.get(position).price);
        holder.num.setText(mList.get(position).num);

        if(NumberManager.isDaYu(mList.get(position).price,last_price)>0)
        {
            holder.price.setTextColor(MResUtil.getUpColor());
        }
        else if(NumberManager.isDaYu(mList.get(position).price,last_price)==0)
        {
            holder.price.setTextColor(MResUtil.getPingColor());
        }
        else
        {
            holder.price.setTextColor(MResUtil.getDownColor());
        }



    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ka=(Activity) parent.getContext();
        //LayoutInflater.from指定写法
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_minxi, parent, false);
        return new MyViewHolder(v);
    }

    /**
     * 设置上一个交易日收盘价格
     */
    public void setLastDayPrice(String price)
    {
        this.last_price=price;
    }



}
